<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header">
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title></title>
	<meta name="keywords" content="">
	<meta name="description" content="">
	<link rel="shortcut icon" href="../../../static/favicon.ico">
	<link rel="stylesheet" href="../../../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" />
	<link rel="stylesheet" href="../../../static/css/layui.css" th:href="@{/css/layui.css}" />
	<link rel="stylesheet" href="../../../static/css/font-awesome.css" th:href="@{/css/font-awesome.css}" />
	<!-- bootstrap-table 表格插件样式 -->
	<link rel="stylesheet" href="../../../static/ajax/libs/bootstrap-table/bootstrap-table.min.css" th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" />
	<link rel="stylesheet" href="../../../static/ajax/libs/jqTreeGrid/jquery.treegrid.css" th:href="@{/ajax/libs/jqTreeGrid/jquery.treegrid.css}" />
	<link rel="stylesheet" href="../../../static/css/animate.css" th:href="@{/css/animate.css}" />
	<link rel="stylesheet" href="../../../static/css/style.css" th:href="@{/css/style.css}" />
	<link rel="stylesheet" href="../../../static/css/checkbox.css" th:href="@{/css/checkbox.css}" />
	<link rel="stylesheet" href="../../../static/ajax/libs/select/select2.css" th:href="@{/ajax/libs/select/select2.css}" />
	<link rel="stylesheet" href="../../../static/ruoyi/css/ry-ui.css" th:href="@{/ruoyi/css/ry-ui.min.css?v=2.1.0}" />
</head>
<link rel="stylesheet" href="../../../static/ajax/libs/iCheck/custom.css" th:href="@{/ajax/libs/iCheck/custom.css}" />
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-sysUser-edit" th:object="${sysUser}">
			<input name="userId"  type="hidden"  th:field="*{userId}" />
			<input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
			<div class="form-group">
				<label class="col-sm-3 control-label ">登录名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" readonly="true" th:field="*{loginName}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">部门名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeName" th:field="*{dept.deptName}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">用户名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="userName" id="userName" th:field="*{userName}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">游戏角色ID：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="playerId" id="playerId" th:field="*{playerId}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">邮箱：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="email" id="email" th:field="*{email}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">手机：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="mobileNo" id="mobileNo" th:field="*{mobileNo}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">性别：</label>
				<div class="col-sm-8">
					<select id="sex" class="form-control m-b">
						<option value="0" th:field="*{sex}">男</option>
						<option value="1" th:field="*{sex}">女</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
                         <input type="checkbox" th:checked="${sysUser.status == '0' ? true : false}" class="onoffswitch-checkbox" id="status" name="status">
                         <label class="onoffswitch-label" for="status">
                             <span class="onoffswitch-inner"></span>
                             <span class="onoffswitch-switch"></span>
                         </label>
                     </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">角色：</label>
				<div class="col-sm-8">
					<label th:each="role:${roles}" class="checkbox-inline i-checks">
						<input name="role" type="checkbox" th:value="${role.roleId}" th:text="${role.roleName}" th:checked="${role.flag}">
					</label>
				</div>
			</div>

			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script>
        $("#form-sysUser-edit").validate({
        	rules:{
        		userName:{
        			required:true,
        		},
        		deptName:{
        			required:true,
        		}
        	},
        	submitHandler:function(form){
        		edit();
        	}
        });

        function edit() {
        	var userId = $("input[name='userId']").val();
        	var deptId = $("input[name='deptId']").val();
            var playerId = $("input[name='playerId']").val();
        	var userName = $("input[name='userName']").val();
        	var email = $("input[name='email']").val();
        	var mobileNo = $("input[name='mobileNo']").val();
        	var sex = $("#sex option:selected").val();
        	var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
        	var roleIds = $.form.selectCheckeds("role");
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "system/sysUser/save",
        		data : {
        			"userId": userId,
        			"deptId": deptId,
                    "playerId": playerId,
        			"userName": userName,
        			"email": email,
        			"mobileNo": mobileNo,
        			"sex": sex,
        			"status": status,
        			"roleIds": roleIds,
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }

        /*用户管理-修改-选择部门树*/
        function selectDeptTree() {
        	var deptId = $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            $.modal.open("选择部门", url, '380', '380');
        }
    </script>
</body>
</html>
